package com.gm.sfc;

import static com.gm.sfc.util.consts.Consts.*;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;

import com.gm.sfc.logic.DataLogic;

/**
 * The Base of all Activities
 * @author $Author: segen.der.gottin@gmail.com $
 * @version $Revision: 25 $
 */
public class BaseActivity extends Activity {
    protected boolean mIsIFC = false;
    protected static final String EXTRA_DATA = "EXTRA_DATA";
    protected static final String EXTRA_TYPE = "EXTRA_TYPE";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            mIsIFC = true;
        } else {
            mIsIFC = false;
        }
    }

    /**
     * Show Toast
     * @param msg message
     */
    protected void showToast(String msg) {
        Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show();
    }

    /**
     * Show Toast
     * @param msg message
     * @param duration duration
     */
    protected void showToast(String msg, int duration) {
        Toast.makeText(getApplicationContext(), msg, duration).show();
    }

    /**
     * Show Toast when it is in debug mode
     * @param msg message
     */
    protected void showDebugToast(String msg) {
        if (DEBUGGABLE) {
            showToast(msg);
        }
    }

    /**
     * Show Toast when it is in debug mode
     * @param msg message
     * @param duration duration
     */
    protected void showDebugToast(String msg, int duration) {
        if (DEBUGGABLE) {
            showToast(msg, duration);
        }
    }

    public void onClickWeapon(View v) {
        Intent intent = new Intent(getApplicationContext(), DataActivity.class);
        intent.putExtra(EXTRA_TYPE, DataLogic.TYPE_WEAPON);
        startActivity(intent);
    }

    public void onClickHelmet(View v) {
        Intent intent = new Intent(getApplicationContext(), DataActivity.class);
        intent.putExtra(EXTRA_TYPE, DataLogic.TYPE_HELMET);
        startActivity(intent);
    }

    public void onClickArmor(View v) {
        Intent intent = new Intent(getApplicationContext(), DataActivity.class);
        intent.putExtra(EXTRA_TYPE, DataLogic.TYPE_ARMOR);
        startActivity(intent);
    }

    public void onClickOrnament(View v) {
        Intent intent = new Intent(getApplicationContext(), DataActivity.class);
        intent.putExtra(EXTRA_TYPE, DataLogic.TYPE_ORNAMENT);
        startActivity(intent);
    }

    public void onClickMineria(View v) {
        Intent intent = new Intent(getApplicationContext(), DataActivity.class);
        intent.putExtra(EXTRA_TYPE, DataLogic.TYPE_MINERIA);
        startActivity(intent);
    }

    public void onClickSearch(View v) {
        Intent intent = new Intent(getApplicationContext(), SearchActivity.class);
        startActivity(intent);
    }

    public void onClickFavorite(View v) {
        Intent intent = new Intent(getApplicationContext(), FavoriteActivity.class);
        startActivity(intent);
    }

    public void onClickUser(View v) {
        Intent intent = new Intent(getApplicationContext(), UserDetailActivity.class);
        startActivity(intent);
    }

    protected void showKeyboard(View v, boolean show) {
        InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        if (show) {
            inputMethodManager.showSoftInput(v, InputMethodManager.SHOW_FORCED);
        } else {
            inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }
    }
}
